package com.cosina.game.crystallight.ui.mapselect;

import android.content.Context;
import android.graphics.Bitmap;
import android.graphics.Canvas;
import android.graphics.Point;
import android.graphics.drawable.BitmapDrawable;
import android.view.MotionEvent;
import android.view.View;
import android.widget.FrameLayout.LayoutParams;

import com.cosina.game.crystallight.model.profile.ProfileManager;
import com.cosina.game.crystallight.model.profile.SkillManager;
import com.cosina.game.crystallight.ui.ResourceManager;
import com.cosina.game.crystallight.ui.common.PaintSuite;
import com.cosina.game.crystallight.util.CanvasUtil;

public class SkillPart extends View {

	public SkillPart(Context context) {
		super(context);
		this.setLayoutParams(new LayoutParams(LayoutParams.FILL_PARENT, UpAndDownLayout.UP_HEIGHT));
		this.setBackgroundDrawable(new BitmapDrawable(ResourceManager.get("img/map/skillsinfo.jpg")));
		
		skillPointTextLocation = new Point(212,400);
	}
	Bitmap star = ResourceManager.get("img/map/skills_star.png");
	@Override
	protected void onDraw(Canvas canvas) {
		SkillManager skillManager = ProfileManager.getCurrentProfile().skillManager;
		
		int[] levels = skillManager.getSkillLevels();
		for(int i=0; i<5; i++) {
			int level = levels[i];
			for(int levelIndex=0; levelIndex<level; levelIndex++){
				canvas.drawBitmap(star, STARTX + XSPAN * levelIndex, STARTY + YSPAN * i, PaintSuite.p4Simple);
			}
		}
		int skillpoint = skillManager.getSkillPoint();
		
		CanvasUtil.drawText(canvas, skillpoint, skillPointTextLocation, PaintSuite.p4Text, 27);
	}

	
	final int STARTX = 102, STARTY = 47;
	final int XSPAN = 24, YSPAN = 72;
	final Point skillPointTextLocation;
	@Override
	public boolean onTouchEvent(MotionEvent event) {
		if(event.getAction() == MotionEvent.ACTION_UP){
			SkillManager skillManager = ProfileManager.getCurrentProfile().skillManager;
			skillManager.trySkillUp((int)event.getY()/YSPAN);
			this.invalidate();
		}
		return true;
	}
}
